package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.Category;
import com.oocl.euc.core.maintenance.model.SubCategory;
import com.oocl.euc.core.maintenance.repository.CategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class CategoryBuilder {
    private Category category;

    @Autowired
    CategoryRepository categoryRepository;

    public CategoryBuilder defaultBuilder() {
        this.category = new Category();
        this.category.setCategoryId("test categoryId");
        this.category.setCategoryName("test category");
        this.category.setSortSeq(1);
        this.category.setUpdatedAt(new Date());
        return this;
    }

    public CategoryBuilder withSubCategory(List<SubCategory> subCategories) {
        this.category.setSubCategory(subCategories);
        return this;
    }

    public Category getCategory() {
        return category;
    }

    public Category saveToDB(){
        return this.categoryRepository.save(this.category);
    }
}
